package com.design.softwaredesign.service.impl;

import com.design.softwaredesign.entity.Menu;
import com.design.softwaredesign.mapper.BackHomeMapper;
import com.design.softwaredesign.service.BackHomeService;
import com.design.softwaredesign.vo.DataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :WaiterXiaoYY
 * @description: TODO
 * @data :2020/11/3 8:58
 */
@Service
public class BackHomeServiceImpl implements BackHomeService {
    @Autowired
    private BackHomeMapper backHomeMapper;
    @Override
    public DataVo<Menu> getMenu() {
        DataVo dataVo = new DataVo();
        try {
            List<Menu> menuFatherList = backHomeMapper.getFatherMenu();
            for(int i = 0; i < menuFatherList.size(); i++) {
                List<Menu> webMenuChildrenList = backHomeMapper.getChildrenMenu(menuFatherList.get(i).getId());
                menuFatherList.get(i).setChildren(webMenuChildrenList);
            }
            dataVo.setCode(200);
            dataVo.setMsg("获取菜单列表成功");
            dataVo.setData(menuFatherList);
        } catch (Exception e) {
            dataVo.setCode(202);
            dataVo.setMsg("获取菜单列表失败");
            e.printStackTrace();
        } finally {
            return dataVo;
        }
    }
}
